package com.wsc.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.wsc.entity.Teacher;

public interface TeacherRepository extends JpaRepository<Teacher, Integer>, JpaSpecificationExecutor<Teacher> {

	// Page<Teacher> findAll(Specification<Teacher> spec, Pageable pa);

	@Modifying
	@Query(value = "update t_teachers s set s.status = :status where s.cardno = :cardno", nativeQuery = true)
	void OutSwipingCard(@Param("cardno") String cardno, @Param("status") Integer status);

	@Modifying
	@Query(value = "update t_teachers s set s.status = :status where s.cardno = :cardno", nativeQuery = true)
	Integer swipingCard(@Param("cardno") String cardno, @Param("status") Integer status);

	@Query(value = "select * from t_teachers where cardno = :cardno", nativeQuery = true)
	Teacher getTeacherByCardno(@Param("cardno") String cardno);

	// 通过consumelog的卡号查询entity
	Teacher findByCardno(String cardno);

	@Modifying
	@Query(nativeQuery = true, value = ("update t_teachers set status=:status  where id =:id"))
	void updateStatus(@Param("id") Integer id, @Param("status") Integer status);

	/***
	 * 修改status为0
	 */
	@Modifying
	@Query(nativeQuery = true, value = "updatet t_teachers set status = 0")
	void updateAllStatusToZero();

}
